package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result<String> save(@RequestBody DishDTO dishDTO) {

        return dishService.save(dishDTO);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result<String> update(@RequestBody DishDTO dishDTO){
        return dishService.update(dishDTO);
    }


    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(Integer categoryId, Integer page, Integer pageSize, String name , Integer status){
        return  dishService.page(categoryId,page,pageSize,name,status);
    }

    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result<String> deleteByIds(Long[] ids){
        return dishService.deleteByIds(ids);
    }



    @GetMapping("/list")
    @ApiOperation("查询指定分类下的菜品")
    public Result<List<Dish>> list(Integer categoryId){
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list) ;
    }


    @GetMapping("/{id}")
    @ApiOperation("查询指定id的菜品数据")
    public Result<DishVO> getById(@PathVariable Long id){
        return dishService.getById(id);
    }


    @PostMapping("/status/{status}")
    @ApiOperation("起售、停售菜品")
    public Result<String> startOrStop(@PathVariable Integer status,Long id){
        return  dishService.startOrStop(status,id);
    }
}
